package com.spirng.leetcode.day08;

import java.util.ArrayList;
import java.util.List;

public class Test46 {
    public static void main(String[] args) {
        Test46 test46 = new Test46();
        test46.permute(new int[]{1,2,3});
    }
    ArrayList<List<Integer>> lists=new ArrayList<>();
    ArrayList<Integer> list=new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
           backtracking(nums,new int[nums.length]);
           return lists;
    }
    public void backtracking(int [] nums,int [] use){
        if(list.size()==nums.length){
            lists.add(new ArrayList<>(list));
        }
        for (int i = 0; i < nums.length; i++) {
            if(use[i]==1){
                continue;
            }
            list.add(nums[i]);
            use[i]=1;
            backtracking(nums,use);
            list.remove(list.size()-1);
            use[i]=0;
        }
    }
}
